#!/usr/bin/python

###############################################################
## Name       : gen_tc
## Author     : xiaotu
## Time       : 2022-08-07 02:34:27
## Description:
## 
## 
###############################################################

import sys
import os
import re

def input_sys():
    if len(sys.argv) > 2:
        from_tc = sys.argv[1]
        to_tc = sys.argv[2]
    else:
        print("Input error")
        sys.exit(0)
    return from_tc, to_tc

def modify_tc(frm, to):
    frm_key = re.sub("\.sv","",frm)
    frm_uc = frm_key.upper()
    frm_lc = frm_key.lower()

    to_key  = re.sub("\.sv","",to)
    to_uc = to_key.upper()
    to_lc = to_key.lower()

    out_file = []
    with open(frm, "r") as handle:
        hd = handle.readlines()
        for line in hd:
            line = line.strip("\n")
            line = re.sub(frm_uc, to_uc, line)
            line = re.sub(frm_lc, to_lc, line)
            out_file.append(line)
    return out_file

def write_list(lst, out):
    with open(out, "w") as handle:
        for line in lst:
            handle.write(line+"\n")

def main():
    print("%s is working" % __file__)

    from_tc, to_tc = input_sys()
    out_file = modify_tc(from_tc, to_tc)
    write_list(out_file, to_tc)

if __name__ == "__main__":
    main()
